package leetcode.primary;

public class T198 {
    public int rob(int[] nums) {
        if(nums.length==1){
            return nums[0];
        }
        if (nums.length==2){
            return Math.max(nums[0],nums[1]);
        }
        int p = nums[0],q = nums[1],r = nums[2]+nums[0];
        int x ;

        for (int i = 3; i < nums.length; i++) {
            x = nums[i]+Math.max(p,q);
            p = q;q = r;r =x;
        }
        return Math.max(q,r);
    }

    public static void main(String[] args) {
        T198 t198 = new T198();
        int rob = t198.rob(new int[]{1,2,3,1});
        System.out.println(rob);
    }
}
